package msu.ml.core.xml;

import msu.ml.core.*;
import msu.ml.data.*;
import msu.ml.classifiers.*;
import weka.classifiers.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;

/**
 * @author Reginald M Mead
 * @version 1.0
 */
public class MultilayerPerceptronParser implements IClassifierParser
{
	public Classifier parse(Element element)
	{
      NxMultilayerPerceptron classifier = new NxMultilayerPerceptron();

      boolean autoBuild = Boolean.parseBoolean(
					element.getAttribute("auto_build"));
      double learningRate = Double.parseDouble(
					element.getAttribute("learning_rate"));
      boolean decay = Boolean.parseBoolean(
					element.getAttribute("decay"));
      String hiddenLayers = element.getAttribute("hidden_layers");
      int trainingTime = Integer.parseInt(
					element.getAttribute("training_time"));
      boolean normalizeAttributes = Boolean.parseBoolean(
					element.getAttribute("normalize_attributes"));
      int validationSetSize = Integer.parseInt(
					element.getAttribute("validation_set_size"));

      classifier.setAutoBuild(autoBuild);
      classifier.setLearningRate(learningRate);
      classifier.setDecay(decay);
      classifier.setHiddenLayers(hiddenLayers);
      classifier.setTrainingTime(trainingTime);
      classifier.setNormalizeAttributes(normalizeAttributes);
      classifier.setValidationSetSize(validationSetSize);

      if(ApplicationSettings.getInstance().getConfig("verbose").equals("true"))
      {
         System.out.println("Multilayer Perceptron");
         System.out.println("\t Auto Build: " + autoBuild);
         System.out.println("\t Learning Rate: " + learningRate);
         System.out.println("\t Decay: " + decay);
         System.out.println("\t Hidden Layers: " + hiddenLayers);
         System.out.println("\t Training Time: " + trainingTime);
         System.out.println("\t Normalize Attributes: " + normalizeAttributes);
         System.out.println("\t Validation Set Size: " + validationSetSize);
      }

      return classifier;
   }
}
